package com.jcxy.service.impl;

import com.jcxy.VO.NotifyVo;
import com.jcxy.mapper.NotifyMapper;
import com.jcxy.service.NotifyService;
import com.jcxy.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class NotifyServiceImpl implements NotifyService {

    @Autowired
    private NotifyMapper notifyMapper;

    @Override
    public PageBean queryListByPage(Map dto, Integer page, Integer limit) {

        Integer count = notifyMapper.queryNotifyCount(dto);
        PageBean pageBean = new PageBean(page, limit);
        dto.put("pageIndex",pageBean.getPageIndex());
        dto.put("limit",pageBean.getLimit());
        List<NotifyVo> statusList = notifyMapper.queryNotifyByPage(dto);

        pageBean.setResponseData(count,statusList);
        return pageBean;
    }

    @Override
    @Transactional
    public int updateNotifyById(Map dto) throws Exception {

        int count = notifyMapper.updateStatus(dto);
        if(count > 1){
            throw new Exception("更新公告信息异常！");
        }
        return count;
    }

    @Override
    @Transactional
    public void insertNotify(Map dto) throws Exception {

        notifyMapper.insertNotify(dto);
    }

    @Override
    @Transactional
    public int deleteNotifyById(Integer notify_id) throws Exception {

        int count = notifyMapper.deleteNotifyById(notify_id);
        if(count > 1){
            throw new Exception("删除通知信息异常！");
        }
        return count;
    }
}
